package changceilingcolor003;

import java.util.ArrayList;
import java.util.HashMap;

import controlP5.ControlEvent;
import controlP5.ControlP5;
import controlP5.ControlWindow;
import controlP5.Controller;
import processing.core.PApplet;
import peasy.*;
import peasy.org.apache.commons.math.geometry.Rotation;
import toxi.geom.*;
import plethora.core.*;
import GraphTheoryTools.*;
import java.util.Timer;
import peasy.PeasyCam;
//import physicsterm202.SpringClass;
import processing.core.PApplet;
import toxi.geom.Vec3D;
import toxi.physics.VerletPhysics;
import toxi.physics.VerletSpring;
import toxi.physics.behaviors.GravityBehavior;
import toxi.processing.ToxiclibsSupport;
import toxi.physics.*;
import toxi.physics.constraints.*;
import toxi.physics.behaviors.*;
import processing.opengl.*;


@SuppressWarnings("serial")
public class ChangCeilingColor003 extends PApplet {

	//DECLARE LIBRARIES
	PeasyCam cam;
	ControlP5 controlP5;
	ControlP5 controlP5_2;
	ControlWindow ctrlWin;
	ControlWindow ctrlWin1;
	World myWorld;
	Environment environment; 
	Grid grid;
	Ple_Terrain pTerr;
	VerletPhysics physics;
	VerletParticle particles;
	Creator unit;
	
	//DirectedGraph = null;


	//GLOBALS
	public int width= 450;
	public int height= 250;
	int resulotion=5;
	int COLS=width/5;
	int ROWS=height/5;
	int pop=40;

	float pe_sep = 5.0f;
	float pe_coh = 0.5f;
	float pe_ali = 1.0f;
	float pe_sepA = 10.0f;
	float pe_sepB = 10.0f;

	//float  attention_radios1 = 50; 




	boolean showTrail=false;
	boolean showDetail = false;
	boolean showPerson = true;
	boolean showBoundary=true;
	boolean showAlarm = false;
	boolean SomehowWorkFast = false;
	boolean a_active = false;

	//SLIDER	
	//Vistor
	boolean Vistor= true;
	int Capacity_1=100;
	float Attract_to_art_1 = 5.0f;
	float ArtScent_1 = 0;
	float Attract_to_Social_1 = 7.0f;
	float SocialSent_1 = 7;
	float Attract_to_Dealer_1 = 0;
	float DealerSent_1 = 0;
	float Go_to_Destination_1=1;

	//Artist
	boolean Artist = true;
	int Capacity_2=40;
	float Attract_to_art_2 = 0.6f;
	float ArtScent_2 = 0;
	float Attract_to_Social_2 = 0.2f;
	float SocialSent_2 = 1;
	float Attract_to_Dealer_2 = 0.8f;
	float DealerSent_2 = 4;
	float Go_to_Destination_2=0.5f;

	//Dealer
	boolean Dealer = true;
	int Capacity_3=10;
	float Attract_to_art_3 = 0.6f;
	float ArtScent_3 = 4;
	float Attract_to_Social_3 = 0.2f;
	float SocialSent_3 = 0;
	float Attract_to_Dealer_3 = 0.8f;
	float DealerSent_3 = 0;
	float Go_to_Destination_3=0.5f;




	boolean PausePeople = false;
	boolean Switch=true;

	//ARRAYLISTS
	ArrayList<Vec3D> alisOrigin =new ArrayList<Vec3D>();
	ArrayList<Vec3D> alisOrigin1 =new ArrayList<Vec3D>();
	ArrayList<Vec3D> alisOrigin2 =new ArrayList<Vec3D>();
	ArrayList<Vec3D> alisOrigin3 =new ArrayList<Vec3D>();
	ArrayList<Actors> alisPeop =new ArrayList<Actors>();
	ArrayList<Vec3D> alisBnd1 =new ArrayList<Vec3D>();
	ArrayList<Vec3D> alisBnd2 =new ArrayList<Vec3D>();
	ArrayList<Vec3D> alisBnd3 =new ArrayList<Vec3D>();
	ArrayList<Actors> alisDst =new ArrayList<Actors>();
	ArrayList<Creator> alisUnit =new ArrayList<Creator>();
	//ArrayList <SpringClass> springs;
	HashMap<String, Attraction> AttractionDictionary= new HashMap<String, Attraction>();

	AttractionInteractionHolder AttractionInteractionPropertiesHolder = null;


	ArrayList <Ple_Agent> boids;
	ArrayList<Actors> AllActiveActors = new ArrayList<Actors>();
	static ChangCeilingColor003 m_This = null;
	public static ChangCeilingColor003 GetInstance()
	{
		if(m_This == null)
		{
			m_This =  new ChangCeilingColor003();
		}
		return m_This;
	}

	public void setup() {

		boolean HidePeopleForDevelopment = false;	
		if(HidePeopleForDevelopment )
		{
			Vistor = false;
			Artist  = false;
			Dealer = false;
		}

		size(900, 900, P3D);
		frameRate(20);
		initializeCamera();

		environment=new Environment(this);
		myWorld = new World(this);
		grid=new Grid(this, COLS, ROWS);
		
		sliders();
		//sliders2(); 


		myWorld.init();
		grid.init();
		
		///////////////////////////////////////////////////////////spring
		physics = new VerletPhysics();
		//Vec3D cen=new Vec3D(0, 0, 0);
		//float radius=0.0f;
		 //unit=new Creator(this,cen,radius);
		for (int i =0; i<alisDst.size(); ++i){
			Attraction att =  (Attraction) alisDst.get(i);
		 Vec3D cen= att.GetLocation().copy();
		 float radius=(float) att.GetAttractionRadious();
		 boolean u_active=att.m_active;
		 int uColor_R=att.GetColorR();
			int uColor_G=att.GetColorG();
			int uColor_B=att.GetColorB();
		 unit=new Creator(this,cen,radius,u_active,uColor_R,uColor_G,uColor_B);
		 alisUnit.add(unit);
		 
		}
	
		  //Vec3D v=new Vec3D(0, 0, -0.01f);
		  //GravityBehavior g=new GravityBehavior(v);
		  //physics.addBehavior(g);
		
		
		Vec3D location = new Vec3D(0, 0, 0);
		pTerr = new Ple_Terrain(this, location, COLS, ROWS, resulotion, resulotion);

		CL();
		R();
		S();
		RA();



		//		Node.setPAppletParent(this);
		//		g = new DirectedGraph();
		//		  int padding = 10;
		//		Node n1 = new Node("1",padding ,padding);
		//		  Node n2 = new Node("2",padding,height-padding);
		//		  Node n3 = new Node("3",width-padding,height-padding);
		//		  Node n4 = new Node("4",width-padding,padding);
		//		  Node n5 = new Node("5",width-3*padding,height-2*padding);
		//		  Node n6 = new Node("6",width-3*padding,2*padding);
		//
		//		  // add nodes to graph
		//		  g.addNode(n1);
		//		  g.addNode(n2);
		//		  g.addNode(n3);
		//		  g.addNode(n4);
		//		  g.addNode(n5);
		//		  g.addNode(n6);
		//		  
		//		  // link nodes
		//		  g.linkNodes(n1,n2);
		//		  g.linkNodes(n2,n3);
		//		  g.linkNodes(n3,n4);
		//		  g.linkNodes(n4,n1);
		//		  g.linkNodes(n1,n3);
		//		  g.linkNodes(n2,n4);
		//		  g.linkNodes(n5,n6);
		//		  g.linkNodes(n1,n6);
		//		  g.linkNodes(n2,n5);
		//		  
		//		  g.draw();

	}

	void CL()
	{
		for (int i=0;i<alisPeop.size();i++) {
			alisPeop.remove(i);
		}
	}


	void R()
	{
		for (int i=0;i<alisPeop.size();i++) {
			alisPeop.remove(i);		
		}
		//AllActiveActors2.clear();
		//AllActiveActors.clear();

		myWorld = new World(this);
		myWorld.init();

		showPerson=true;
	}

	void S(){
		showBoundary=!showBoundary;

	}

	void RA()
	{

		///This part is unnecessary since the location delta is zero by default  
		//		for(int i =0; i<alisDst.size(); ++i)
		//		{			
		//			Actors att = alisDst.get(i);
		//			att.SetDeltaX(0);
		//			att.SetDeltaY(0);
		//			att.SetDeltaZ(0);			
		//		}
	}



	void ResumePeople()
	{
		PausePeople = false;
	}


	public void draw() {
		background(0);
		smooth();

		for (int i=0;i<AllActiveActors.size();i++) {
			AllActiveActors.get(i).Draw();
		}
		environment.run();

		if (showPerson==true){
			myWorld.run();
		}

		if(!SomehowWorkFast)
		{
		grid.run();
		grid.clear();
		}

///////////////////////////////////////////////////////////spring
		for (int i =0; i<alisUnit.size(); ++i){

			Creator unit =  (Creator) alisUnit.get(i);
			Attraction att =  (Attraction) alisDst.get(i);
			unit.cen= att.GetLocation().copy();
			unit.radius=(float) att.GetAttractionRadious();
			unit.u_active=att.m_active;
			 //if(att.GetId()=="A"||att.GetId()=="B"){
			if(i==0||i==1||i==10||i==11||i==12){
			unit.u_active=att.m_active;
			  }else{
				  unit.u_active=false;  
			}
			unit.uColor_R=att.GetColorR();
			unit.uColor_G=att.GetColorG();
			unit.uColor_B=att.GetColorB();
			if(unit.u_active==true){	
		  unit.run();
		  if(Switch==true){
		  drawParticles();
		  drawSprings();
		  }
		  physics.update();
		  Switch=false;
		  if(att.m_oldLocation != att.GetLocation())Switch=true; 
		  //physics.clear();
		}
			physics.clear();
		} 

		//g.draw();

		//video
		//saveFrame("Video/frame"+frameCount+".tiff");

	}
///////////////////////////////////////////////////////////spring
	void drawParticles() {
		  for (int i=0;i<physics.particles.size();i++) {
		   VerletParticle vp=(VerletParticle)physics.particles.get(i) ;
		    
		  
		    strokeWeight(2);
		  
		    if (vp.isLocked()) {
		      stroke(255, 0, 0);
		    }
		    else {
		      //stroke(0, 255, 200);
		    	stroke(255,50);
		      //stroke(unit.uColor_R,unit.uColor_G,unit.uColor_B);
		    }
		   point(vp.x, vp.y, vp.z);
		    //strokeWeight(1);
		    //fill(unit.uColor_R,unit.uColor_G,unit.uColor_B,50);
		    //ellipse(vp.x, vp.y, 8,8);
		  }
		}
	
		void drawSprings() {
		  for (int i=0;i<physics.springs.size();i++) {
		    VerletSpring sp=(VerletSpring) physics.springs.get(i) ;
		    stroke(255,50);
		    strokeWeight(1);
		    line(sp.a.x, sp.a.y, sp.a.z, sp.b.x, sp.b.y, sp.b.z);//a,b are the two nodes of spring
		  }
		}

		//void addSpringClass (SpringClass c){
			//springs.add(c);
		//}
		
		
	void initializeCamera() {
		//cam = new PeasyCam(this, 261.94977, 193.22641, 30.904861, 550);
		cam = new PeasyCam(this, 250, 150, 25, 480);
		setCam();

	}
	//
	void setCam() {
		cam.setMinimumDistance(.001);
		cam.setMaximumDistance(10000);
		cam.setRotations(1.4720584, 0.76990885, -3.0659537);
		//cam.setRotations(0, 0, 0);
	}
	//
	void getCamSettings() {  
		float[] cLook = cam.getLookAt();
		float[] cRot = cam.getRotations();
		println( cLook[0] + ", " +  cLook[1]+ ", " +  cLook[2]);
		println( cRot[0] + ", " +  cRot[1]+ ", " +  cRot[2]);
	}
	
	void cam01() {
		  smooth();
		  //cam = new PeasyCam(this, 250.12335, 193.39209, 79.13221, 430);
		  cam = new PeasyCam(this, 226.0749, 193.24638, 48.21127,  500);
		  cam.setRotations(-1.5741906, -0.0016942625, 6.925811E-4);
		  //cam.setRotations(-1.5741906, -0.0016942625, 1.0842037);
		}

		void cam02() {
		  //short elev A
		  smooth();
		  //cam = new PeasyCam(this, 255.10933, 151.74408, 66.02949, 471.9061336023195);
		  cam = new PeasyCam(this, 255.06383, 124.033676, 69.75783, 520);
		  cam.setRotations(-0.8548777, -1.5683312, 0.7143931);
		}

		void cam03() {
		  //short elev B
		  smooth();
		  cam = new PeasyCam(this, 254.88354, 123.08456, 78.0125, 471.827189438525);
		  cam.setRotations(-1.2579124, 1.5604136, -0.3161817);
		}
		void cam04() {
		  //street view
		  smooth();
		  //cam = new PeasyCam(this, 327.7893, 154.66658, 149.73418, 400);
		  //cam.setRotations(2.1098406, 0.7421535, 2.7550817);
		  cam = new PeasyCam(this, 273.71497, 148.01338, 64.25295, 430);
		  cam.setRotations(1.7550573, 0.82828945, 3.0059078);

		}

		void cam05() {
		  //prespective
		  smooth();
		  cam = new PeasyCam(this, 277.3692, 107.12149, 5.1229763, 472);
		  cam.setRotations(0.8242081, 0.5771989, -2.655814);
		}
	


	public void keyPressed() {
		if ( key == ' ')getCamSettings();
		 //camera angles
		  if (key == '1')cam01();
		  if (key == '2')cam02();
		  if (key == '3')cam03();
          if (key == '4')cam04();
		  if (key == '5')cam05();

		  
		if (key=='s') {
			saveFrame("Image/frame"+frameCount+".tiff");
			println(frameCount);
		}
		//agent's trail
		if (key == 't' && showTrail==false) {
			showTrail=true;
		}
		else if (key == 't' && showTrail==true) {
			showTrail=false;
		}

		if (key == 'd')
		{
			if( showDetail==false)
			{  
				showDetail=true;
			}
			else
			{
				showDetail=false;
			}

		}

		if (key == 'a'){
			SomehowWorkFast=!SomehowWorkFast;
		}
	}

	void sliders2() {
		ControlP5 controlP5_2 = new ControlP5(this);
		ControlWindow ctrlWin1 = controlP5_2.addControlWindow("controlP5Window1", 10, 10, 300, 750);

		//Controller ms1 = controlP5_2.addButton("R", 0, 10, 400, 12, 12);
		//ms1.setWindow(ctrlWin1);
		//Controller ms2 =controlP5_2.addTextlabel("Label15","Reset",26,403);
		//ms2.setWindow(ctrlWin1);

		//Controller ms3 = controlP5_2.addButton("CL", 0, 10, 420, 12, 12);
		//ms3.setWindow(ctrlWin1);
		//Controller ms4 =controlP5_2.addTextlabel("Label16","Clear",26,423);
		//ms4.setWindow(ctrlWin1);

		//Controller ms5 = controlP5_2.addButton("S", 0, 10,440, 12, 12);
		//ms5.setWindow(ctrlWin1);	
		//Controller ms333 =controlP5_2.addTextlabel("Label17","Surrounding",26,443);
		//ms333.setWindow(ctrlWin1);

		//Controller ms6 = controlP5_2.addButton("RA", 0, 10,460, 12, 12);
		//ms6.setWindow(ctrlWin1);	
		//Controller ms7 =controlP5_2.addTextlabel("Label18","ResetAttractionPostion",26,463);
		//ms7.setWindow(ctrlWin1);

		//Controller ms8 = controlP5_2.addButton("ResumePeople", 0, 10,480, 12, 12);
		//ms8.setWindow(ctrlWin1);
		//Add every attraction that was read from the file
		int AttractionGUI_x = 10;
		int AttractionGUI_y = 10;
		for(int i=0; i < alisDst.size(); i++)
		{

			if(i>7)
			{
				AttractionGUI_y = (i-8)*120+10;
				AttractionGUI_x = 200;
			}
			else
			{
				AttractionGUI_y = i*120+10;
				AttractionGUI_x = 10;
			}
			Attraction att =  (Attraction) alisDst.get(i);
			AddAtrractionToGUI2(ctrlWin1,controlP5_2 , att, AttractionGUI_x,AttractionGUI_y);
		}


	}

	private void AddAtrractionToGUI2(ControlWindow ctrlWin,ControlP5 _controlP5, Attraction attraction,int x,int y)
	{
		//Controller ms0 = _controlP5.addTextlabel(attraction.GetId()+"Label", attraction.GetDescription(),x+12,y+14 );
		Controller ms0 = _controlP5.addTextlabel(attraction.GetId()+"Label", attraction.GetDescription(),x+12,y+2);
		ms0.setWindow(ctrlWin);

		Controller ms1 = _controlP5.addToggle(attraction.GetId() + "_",attraction.m_active, x, y, 10, 10); 
		ms1.setWindow(ctrlWin);

		//stroke(255,255,255);//////////////////////////////////////////////////////////////
		//text(attraction.GetArea(),x,y+22);

		//Controller ms2 = _controlP5.addNumberbox("",attraction.GetArea(), x, y + 30, 10, 10);
		//ms2.setWindow(ctrlWin);/////////////////////////////////////

	}





	void sliders() {
		ControlP5 controlP5 = new ControlP5(this);
		ControlWindow ctrlWin = controlP5.addControlWindow("controlP5Window", 10, 10, 750, 800);		
		/////////////////////////addSlider(theName, theMin, theMax, theDefaultValue, theX, theY, theWidth, theHeight);
		//Vistor
		Controller ms1 = controlP5.addToggle("Vistor", true, 10,10, 10, 10); 
		ms1.setWindow(ctrlWin);

		Controller ms1001 =controlP5.addTextlabel("Label11","Vistor",22,12);
		ms1001.setWindow(ctrlWin);

		Controller ms9 = controlP5.addSlider("Go to Destination_1", 0, 2, Go_to_Destination_1, 10, 24, 70, 10); 
		ms9.setWindow(ctrlWin);

		Controller ms2 = controlP5.addSlider("Capacity_1", 0, 100,Capacity_1, 200,24, 70, 10);
		ms2.setWindow(ctrlWin);

		Controller ms1101 =controlP5.addTextlabel("Label14","Desire",10,48);
		ms1101.setWindow(ctrlWin);

		Controller ms1111 =controlP5.addTextlabel("Label144","Attrat",200,48);
		ms1111.setWindow(ctrlWin);

		Controller ms3 = controlP5.addSlider("Attract to_art_1", 0, 10, Attract_to_art_1, 10, 60, 70, 10);
		ms3.setWindow(ctrlWin);

		Controller ms4 = controlP5.addSlider("ArtScent_1", 0, 10, ArtScent_1, 200, 60, 70, 10);
		ms4.setWindow(ctrlWin);

		Controller ms5 = controlP5.addSlider("Attract to_Social_1", 0, 10, Attract_to_Social_1, 10, 80, 70, 10); 
		ms5.setWindow(ctrlWin);

		Controller ms6 = controlP5.addSlider("SocialSent_1", 0, 10, SocialSent_1, 200, 80, 70, 10); 
		ms6.setWindow(ctrlWin);

		Controller ms7 = controlP5.addSlider("Attract to_Dealer_1", 0, 10, Attract_to_Dealer_1, 10, 100, 70, 10); 
		ms7.setWindow(ctrlWin);

		Controller ms8 = controlP5.addSlider("DealerSent_1", 0, 10, DealerSent_1, 200, 100, 70, 10); 
		ms8.setWindow(ctrlWin);




		//Artist
		Controller ms11 = controlP5.addToggle("Artist", true, 10, 130, 10, 10); 
		ms11.setWindow(ctrlWin);

		Controller ms1002 =controlP5.addTextlabel("Label12","Artist",22,132);
		ms1002.setWindow(ctrlWin);

		Controller ms19 = controlP5.addSlider("Go to Destination_2", 0, 2, Go_to_Destination_2, 10, 144, 70, 10); 
		ms19.setWindow(ctrlWin);

		Controller ms12 = controlP5.addSlider("Capacity_2", 0, 100, Capacity_2, 200, 144, 70, 10);
		ms12.setWindow(ctrlWin);

		Controller ms1202 =controlP5.addTextlabel("Label1144","Desire",10,168);
		ms1202.setWindow(ctrlWin);

		Controller ms1222 =controlP5.addTextlabel("Label1444","Attrat",200,168);
		ms1222.setWindow(ctrlWin);

		Controller ms13 = controlP5.addSlider("Attract to_art_2", 0, 10, Attract_to_art_2, 10, 180, 70, 10);
		ms13.setWindow(ctrlWin);

		Controller ms14 = controlP5.addSlider("ArtScent_2", 0, 10, ArtScent_2, 200, 180, 70, 10);
		ms14.setWindow(ctrlWin);

		Controller ms15 = controlP5.addSlider("Attract to_Social_2", 0, 10, Attract_to_Social_2, 10, 200, 70, 10); 
		ms15.setWindow(ctrlWin);

		Controller ms16 = controlP5.addSlider("SocialSent_2", 0, 10, SocialSent_2, 200, 200, 70, 10); 
		ms16.setWindow(ctrlWin);

		Controller ms17 = controlP5.addSlider("Attract to_Dealer_2", 0, 10, Attract_to_Dealer_2, 10, 220, 70, 10); 
		ms17.setWindow(ctrlWin);

		Controller ms18 = controlP5.addSlider("DealerSent_2", 0, 10, DealerSent_2, 200, 220, 70, 10); 
		ms18.setWindow(ctrlWin);



		//Dealer
		Controller ms21 = controlP5.addToggle("Dealer", true, 10, 250, 10, 10); 
		ms21.setWindow(ctrlWin);

		Controller ms1003 =controlP5.addTextlabel("Label13","Dealer",22,252);
		ms1003.setWindow(ctrlWin);
		Controller ms29 = controlP5.addSlider("Go to Destination_3", 0, 2, Go_to_Destination_3, 10,264, 70, 10); 
		ms29.setWindow(ctrlWin);

		Controller ms22 = controlP5.addSlider("Capacity_3", 0, 100, Capacity_3,200, 264, 70, 10);
		ms22.setWindow(ctrlWin);

		Controller ms1303 =controlP5.addTextlabel("Label1114444","Desire",10,288);
		ms1303.setWindow(ctrlWin);

		Controller ms1333 =controlP5.addTextlabel("Label1111144","Attrat",200,288);
		ms1333.setWindow(ctrlWin);



		Controller ms23 = controlP5.addSlider("Attract to_art_3", 0, 10, Attract_to_art_3, 10, 300, 70, 10);
		ms23.setWindow(ctrlWin);

		Controller ms24 = controlP5.addSlider("ArtScent_3", 0, 10, ArtScent_3, 200, 300, 70, 10);
		ms24.setWindow(ctrlWin);

		Controller ms25 = controlP5.addSlider("Attract to_Social_3", 0, 10, Attract_to_Social_3, 10, 320, 70, 10); 
		ms25.setWindow(ctrlWin);

		Controller ms26 = controlP5.addSlider("SocialSent_3", 0, 10, SocialSent_3, 200, 320, 70, 10); 
		ms26.setWindow(ctrlWin);

		Controller ms27 = controlP5.addSlider("Attract to_Dealer_3", 0, 10, Attract_to_Dealer_3, 10, 340, 70, 10); 
		ms27.setWindow(ctrlWin);

		Controller ms28 = controlP5.addSlider("DealerSent_3", 0, 10, DealerSent_3, 200, 340, 70, 10); 
		ms28.setWindow(ctrlWin);



		Controller ms30 = controlP5.addButton("R", 0, 10, 400, 12, 12);
		ms30.setWindow(ctrlWin);
		Controller ms311 =controlP5.addTextlabel("Label15","Reset",26,403);
		ms311.setWindow(ctrlWin);

		Controller ms300 = controlP5.addButton("CL", 0, 10, 420, 12, 12);
		ms300.setWindow(ctrlWin);
		Controller ms322 =controlP5.addTextlabel("Label16","Clear",26,423);
		ms322.setWindow(ctrlWin);

		Controller ms301 = controlP5.addButton("S", 0, 10,440, 12, 12);
		ms301.setWindow(ctrlWin);	
		Controller ms333 =controlP5.addTextlabel("Label17","Surrounding",26,443);
		ms333.setWindow(ctrlWin);

		Controller ms302 = controlP5.addButton("RA", 0, 10,460, 12, 12);
		ms302.setWindow(ctrlWin);	
		Controller ms344 =controlP5.addTextlabel("Label18","ResetAttractionPostion",26,463);
		ms344.setWindow(ctrlWin);


		Controller ms303 = controlP5.addButton("ResumePeople", 0, 10,480, 12, 12);
		ms303.setWindow(ctrlWin);







		//Controller ms302 = controlP5.addButton("ResetAttractionPostion", 0, 10, 650, 120, 30);
		//ms302.setWindow(ctrlWin);	


		//Add every attraction that was read from the file
		int AttractionGUI_x = 400;
		int AttractionGUI_y = 10;
		for(int i=0; i < alisDst.size(); i++)
		{

			if(i>6)
			{
				AttractionGUI_y = (i-7)*120+10;
				AttractionGUI_x = 600;
			}
			else
			{
				AttractionGUI_y = i*120+10;
				AttractionGUI_x = 400;
			}
			Attraction att =  (Attraction) alisDst.get(i);
			AddAtrractionToGUI(ctrlWin,controlP5 , att, AttractionGUI_x,AttractionGUI_y);
		}



	}

	private void AddAtrractionToGUI(ControlWindow ctrlWin,ControlP5 _controlP5, Attraction attraction,int x,int y)
	{



		//Controller ms0 = _controlP5.addTextlabel(attraction.GetId()+"Label", attraction.GetDescription(),x+12,y+14 );
		Controller ms0 = _controlP5.addTextlabel(attraction.GetId()+"Label", attraction.GetDescription(),x+12,y+2);
		ms0.setWindow(ctrlWin);

		Controller ms31 = _controlP5.addToggle(attraction.GetId() + "_",attraction.m_active, x, y, 10, 10); 

		ms31.setWindow(ctrlWin);

		Controller ms32 = _controlP5.addSlider(attraction.GetId()+"_Range",(float)(attraction.m_Min_r),((float)attraction.m_Max_r),(int)attraction.AttractionRadious, x, y + 30, 70, 10);
		ms32.setWindow(ctrlWin);

		//Controller ms33 = _controlP5.addSlider(attraction.GetId()+"_X", attraction.m_Min_x,attraction.m_Max_x, 0, x, y + 50, 70, 10);
		Controller ms33 = _controlP5.addSlider(attraction.GetId()+"_X", (float)(attraction.m_Min_x),((float)attraction.m_Max_x), attraction.GetLocation().x, x, y + 50, 70, 10);
		ms33.setWindow(ctrlWin);

		Controller ms34 = _controlP5.addSlider(attraction.GetId()+"_Y", (float)(attraction.m_Min_y),((float)attraction.m_Max_y), attraction.GetLocation().y, x,y + 70, 70, 10);
		ms34.setWindow(ctrlWin);

		Controller ms35 = _controlP5.addSlider(attraction.GetId()+"_Z", (int)(attraction.m_Min_z),((int)attraction.m_Max_z), attraction.GetLocation().z, x, y + 90, 70, 10);
		ms35.setWindow(ctrlWin);


	}







	//This part can deal with changes in the GUI(Slider, button and so on)
	public void controlEvent(ControlEvent theEvent) {

		if(theEvent.isController()) 
		{ 
			String [] fields = PApplet.split(theEvent.controller().name(), '_');

			if(fields.length <2)
				return;



			if(fields[1].equals(""))
			{
				Attraction att = AttractionDictionary.get(fields[0]);
				//print("control event from : "+fields[0] );
				if(theEvent.controller().value() == 1.0)
				{
					att.m_active = true;
				}
				else
				{
					att.m_active = false;
				}
				//
			}
			else if(fields[1].equals("Range"))
			{
				Actors att = AttractionDictionary.get(fields[0]);
				att.SetAttractionRadious(theEvent.controller().value());
			}
			else if(fields[1].equals("X"))
			{
				Actors att = AttractionDictionary.get(fields[0]);
				att.SetX(theEvent.controller().value());
			}
			else if(fields[1].equals("Y"))
			{
				Actors att = AttractionDictionary.get(fields[0]);
				att.SetY(theEvent.controller().value());
			}
			else if(fields[1].equals("Z"))
			{
				Actors att = AttractionDictionary.get(fields[0]);
				if(theEvent.controller().value()%20==0){
					att.SetZ(theEvent.controller().value());
				}
			}			


		}
	}

}
